home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
getkey.arc
/
GETKEY.DOC
< prev
next >
Wrap
Text File
|
1989-02-22
|
5KB
|
192 lines
________________________________________________________________
GETKEY DOCumentation
________________________________________________________________
GETKEY is used in batch files to get keys from the keyboard and
exit with an ERRORLEVEL that can then be tested. A prompt line
can be displayed. Any alphanumeric character can be a valid
response but valid responses must be specified on the command
line. An Enter exits with an ERRORLEVEL equal to the last valid
response character on the command line. By using the /F command
line option, all unshifted function keys become valid responses.
Non-valid responses cause the bell to be sounded.
Command line format:
GETKEY [/F] "prompt" [xyz]
where xyz are valid response characters. All characters are
converted to uppercase so you do not have to worry about case
conversion. The last character entered will be the default if
Enter is pressed.
The string between the quotes will be displayed as the prompt
line.
If the /F (or /f) option is used, F1 - F10 become valid
responses.
Return ERRORLEVELS
Function keys return their extended code plus 100.
F1 159 F2 160 F3 161 F4 162 F5 163 F6 164
F7 165 F8 166 F9 167 F10 168
Alphabetical characters "a - z" and "A - Z" are converted to
ERRORLEVELS of 65 - 90 respectively.
Remember that ERRORLEVELS must be tested from the highest to the
lowest value. This is a DOS "feature".
GETKEY entered with no command line parameters will cause the
program to exit with an ERRORLEVEL of 0 and print:
Useage: GETKEY [/F] "Prompt" [XYZ]',13,10,'$'
Some Examples
Here is a simple (minded) batch file do demo the use of GETKEY
using the /F option. You can cut it out with and editor and
execute it if you desire.
MYMENU.BAT
echo off
:begin
cls
Echo.
Echo.
Echo MY MENU
Echo.
Echo F1 Directory
Echo F2 Wide Directory
Echo F3 Print Directory
Echo F4 Save Dir to MYDIR
Echo F5 Directory of A:
Echo F6 CHKDSK
Echo F7 Date
Echo F8 Time
Echo F9 DOS Version
Echo F10 Exit to DOS
Echo.
GETKEY /F " Select: "
if ERRORLEVEL==168 goto exit
if ERRORLEVEL==167 goto version
if ERRORLEVEL==166 goto time
if ERRORLEVEL==165 goto date
if ERRORLEVEL==164 goto chkdsk
if ERRORLEVEL==163 goto dira
if ERRORLEVEL==162 goto dirsave
if ERRORLEVEL==161 goto printdir
if ERRORLEVEL==160 goto dirwide
if ERRORLEVEL==159 goto dir
goto begin
:dir
echo.
dir /p
pause
goto begin
:dirwide
echo.
dir /w/p
pause
goto begin
:printdir
echo.
dir > lpt1
goto begin
:dirsave
echo.
dir > mydir
goto begin
:dira
echo.
dir a: /p
pause
goto begin
:chkdsk
echo.
chkdsk
pause
goto begin
:date
echo.
date
pause
goto begin
:time
echo.
time
pause
goto begin
:version
echo.
ver
pause
goto begin
:exit
echo.
Echo Have a nice day!
If you don't use all of the funtion keys, test for the lowest
value you DON'T want and do a "goto begin".
Example 2
Here is a very simple batch file to illustrate the valid options
and the default enter. With this batch file, and Enter is the
same as a Yes answer.
DIRP.BAT
Echo off
CLS
echo.
echo.
echo.
GETKEY "Do you want a DIRectory? [Y/n] " ny
if ERRORLEVEL==89 goto yes
goto exit
:yes
echo.
echo.
dir /p
:exit
Note also that only the "Y" is tested for. The "N" is the only
other option so it is not necessary to test for it.
Disclaimer
This program is donated to the public domain. Since no fee is
requested, no responsibility on my part is assumed. Use this
program entirely at your own risk. By using this program you
assume ALL responsibility for ANYTHING that happens. While this
program works fine on my AT compatible, it may not on your
system. The only thing promised is that it will take up space on
your disk!
\/\/alter